package com.informationsystem.model;

import static javax.persistence.GenerationType.IDENTITY;

import com.informationsystem.model.BaseObject;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="attachement")
@Indexed
@XmlRootElement
public class Attachement extends BaseObject implements Serializable {
    private Long id;
    private Notice notice;
    private String filename;

    @Id  @GeneratedValue(strategy=IDENTITY) @DocumentId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="notice_id", nullable=false)
    public Notice getNotice() {
        return this.notice;
    }
    
    public void setNotice(Notice notice) {
        this.notice = notice;
    }
    
    @Column(name="filename", nullable=false, length=100)
    @Field
    public String getFilename() {
        return this.filename;
    }
    
    public void setFilename(String filename) {
        this.filename = filename;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Attachement pojo = (Attachement) o;

        if (notice != null ? !notice.equals(pojo.notice) : pojo.notice != null) return false;
        if (filename != null ? !filename.equals(pojo.filename) : pojo.filename != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (notice != null ? notice.hashCode() : 0);
        result = 31 * result + (filename != null ? filename.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("notice").append("='").append(getNotice()).append("', ");
        sb.append("filename").append("='").append(getFilename()).append("'");
        sb.append("]");
      
        return sb.toString();
    }
}
